const hotShowModel = require('../model/hotShowModel');
//查询
module.exports.find = async function (searchObj, page) {
    let { current, pageSize } = page;
    //根据查询条件获取总数
    let total = await hotShowModel.countDocuments(searchObj);
    //根据查询条件获取具体数量的数据
    let data = await hotShowModel.find(searchObj)
        .populate({ path: "films" })
        .limit(pageSize)
        .skip((current - 1) * pageSize);
    return {
        current, pageSize, total, rows: data
    }
};

module.exports.findAll = async function () {
    return await hotShowModel.find();
}

//增加
module.exports.insert = async function (films) {
    return await hotShowModel.create(films);
};
//删除
module.exports.remove = async function (id) {
    return await hotShowModel.remove({ _id: id });
    //deleteOne：删除第一个
    //deleteMany:删除多个
};
//查询id
module.exports.findById = async function (id) {
    return await hotShowModel.findById(id);
};
//修改
module.exports.update = async function (id, films) {
    return await hotShowModel.updateOne({ _id: id }, films);
}

